<template>
  <el-container>
    <el-aside width="200px">
      <CompanyMenu></CompanyMenu>
    </el-aside>
    <div style="width: 100%;margin-left:50px">
      <el-table :data="tableData" style="width: 100%;height:600px">
        <el-table-column width="50" type="index" />
        <el-table-column prop="name" label="名称" width="250" />
        <el-table-column prop="company.introduction" label="企业" width="250" />
        <el-table-column prop="sort" label="排序" width="250" />
        <el-table-column label="操作" width="120">
          <template #default="scope">
            <el-button type="text" size="small" @click="del(scope.$index,scope.row)">删除</el-button>
            <el-button type="text" size="small" @click="edit(scope.$index,scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <edit-dialog ref="dialog"></edit-dialog>
      <el-pagination background @current-change="currentChange" :total="count" :current-page="pageNum" :page-size="pageSize" layout="prev, pager, next">
      </el-pagination>
    </div>
  </el-container>
</template>

<script>
import CompanyMenu from '@/components/menu/CompanyMenu.vue'
import instanceToken from '@/utlis/tokenIdentify.js'
import EditDialog from '@/components/leader/department/EditDialog.vue'

export default {
  name: '',
  components: {
    CompanyMenu,
    EditDialog
  },
  data() {
    return {
      tableData: [{}],
      count: 0,
      pageNum: 1,
      pageSize: 9,
      companyId:'',
      companyUserId:''
    };
  },
  created() {
    this.findAll();
  },
  methods: {
    findAll() {
        instanceToken.get("/department/leader/list", {
          params: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
          }
        }).then(res => {
          this.tableData = res.data.data.list;
          this.count = res.data.data.total;
        })
    },

    //分页
    currentChange(val) {
      this.pageNum = val;
      this.findAll();
    },

    //删除
    del(index, row) {
      var id = row.id;
      this.$confirm('此操作将删除这个部门, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
        instanceToken.get("/department/leader/del/" + id).then(res => {
          this.findAll();
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },

    //修改
    edit(index,row) {
      var id = row.id;
      this.$refs.dialog.show()
      this.$refs.dialog.initdata(id);
    }
  },

}
</script>
